#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import os
import sys

current_dir = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(current_dir)[0]
sys.path.append(rootPath)
from flask import Flask
from utils import read_config
from webs.service import start_stop_service

app = Flask(__name__)
base_path = os.path.join(os.getcwd().split('StockMonitor')[0] + 'StockMonitor')
mark_path = os.path.join(read_config.data_path, 'webs', 'mark', 'project')

p_name = 'start_stop_web'


@app.route('/restart/index', methods=['get'])
def restart_index_service():
    # 等待10秒
    start_stop_service.restart(p_name)
    return 'success'


@app.route('/restart/stop/<pname>', methods=['get'])
def restart_stop_service(pname):
    # 等待10秒
    start_stop_service.stop(pname)
    return 'success'


def run():
    flag = start_stop_service.record_pid(p_name)
    if flag == 1:
        app.run(host='0.0.0.0', port=8888)


if __name__ == "__main__":
    print('')
    run()
